package com.exsun.ex1077.network.entity

import com.exsun.ex1077.model.MenuPermission

/**
 * 描述：
 * 作者：ZhangPing
 * 创建时间：2023/11/8 16:11
 */

//{
//    "menuType": "C",
//    "perms": "app:equipment:list",
//    "id": "2372",
//    "parentId": "2371",
//    "ancestors": null,
//    "label": "设备管理",
//    "type": null,
//    "children": []
//}

data class MenuTree(
    val menuType: String = "",
    val perms: String = "",
    val id: String = "",
    val parentId: String = "",
    val ancestors: String = "",
    val label: String = "",
    val children: List<MenuTree>? = null
){
    fun toMenuPermission(): MenuPermission{
        val permission = MenuPermission()
        if (children.isNullOrEmpty()) return permission
        permission.add = children.count { it.perms.endsWith(":add") } > 0
        permission.edit = children.count { it.perms.endsWith(":edit") } > 0
        permission.remove = children.count { it.perms.endsWith(":remove") } > 0
        permission.rename = children.count { it.perms.endsWith(":rename") } > 0
        return permission
    }
}